﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace FoodManager
{
    public partial class frBaoCaoCongNo : Form
    {
        public frBaoCaoCongNo()
        {
            InitializeComponent();
        }

        private void frBaoCaoCongNo_Load(object sender, EventArgs e)
        {
            // TODO: This line of code loads data into the 'db.tblkhachhang' table. You can move, or remove it, as needed.
            this.tblkhachhangTableAdapter.Fill(this.db.tblkhachhang);

        }

        private void btnThongKe_Click(object sender, EventArgs e)
        {
            dbTableAdapters.tblordersTableAdapter daorder = new dbTableAdapters.tblordersTableAdapter();
            dbTableAdapters.tblorderdetailsTableAdapter daorderdetail = new dbTableAdapters.tblorderdetailsTableAdapter();
            db.tblordersDataTable data = new db.tblordersDataTable();
            if (cbKhachHang.Text.ToLower() == "tất cả")
            {
                daorder.FillByidkhachhangandtrangthai(data, 0, Convert.ToByte(1));
            }
            else
            {
                if (cbKhachHang.SelectedValue != null)
                {
                    daorder.FillByidkhachhangandtrangthai(data, Convert.ToInt32(cbKhachHang.SelectedValue), Convert.ToByte(1));
                }
                else MessageBox.Show("Bạn chọn sai tên khách hàng.");
            }
            data.Columns.Add("thanhtien");
            foreach (DataRow r in data.Rows)
            {
                r["thanhtien"] = daorderdetail.GetTotalPriceOrder(Convert.ToInt32(r["id"]));
            }
            gridControl1.DataSource = data;
        }

        private void btnXuatExcel_Click(object sender, EventArgs e)
        {
            SaveFileDialog d = new SaveFileDialog();
            d.FileName = "bao cao cong no.xlsx";
            d.Filter = "Excel2007|*.xlsx|All files (*.*)|*.*";
            if (d.ShowDialog() == DialogResult.OK)
            {
                gridControl1.ExportToXlsx(d.FileName);
            }
        }
    }
}
